namespace pos.entity
{
using System;
using System.Data;
using System.Configuration;
using System.Text;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Criterion;
/// <summary>
/// t_dealer 的摘要说明
/// </summary>
public class t_dealer:IEntityUtil
{
//   状态值的哈希表 
	private static Hashtable m_enum_state;
	public static Hashtable  enum_state
	{
		get{return m_enum_state;}
	}
	public const int NORMAL=101;
	public const int STOP=100;
	//   列名称哈希表 
	private static Hashtable m_colLabels;    	 
	public static Hashtable colLabels//
	{
		get{return m_colLabels;}
	}
	//表字段名称哈希表
	private static ArrayList m_colNames;     
	public static ArrayList  colNames　
	{
		get{return m_colNames;}
	}
	private Dealer __dealer;
	public long seqID  
	{
		get{return __dealer.seqID;}
		set{ __dealer.seqID=value;}
	}
	public String companyName  
	{
		get{return __dealer.companyName;}
		set{ __dealer.companyName=value;}
	}
	public String linkman1  
	{
		get{return __dealer.linkman1;}
		set{ __dealer.linkman1=value;}
	}
	public String linkman2  
	{
		get{return __dealer.linkman2;}
		set{ __dealer.linkman2=value;}
	}
	public String telephone1  
	{
		get{return __dealer.telephone1;}
		set{ __dealer.telephone1=value;}
	}
	public String telephone2  
	{
		get{return __dealer.telephone2;}
		set{ __dealer.telephone2=value;}
	}
	public String mobile1  
	{
		get{return __dealer.mobile1;}
		set{ __dealer.mobile1=value;}
	}
	public String mobile2  
	{
		get{return __dealer.mobile2;}
		set{ __dealer.mobile2=value;}
	}
	public String remark  
	{
		get{return __dealer.remark;}
		set{ __dealer.remark=value;}
	}
	public int state  
	{
		get{return __dealer.state;}
		set{ __dealer.state=value;}
	}
	private static  DealerDao dao=(DealerDao)SpringContext.Context.GetObject("DealerDao");
	public static DealerDao DAO
	{
		get{return dao;}
		
	}
	
	public t_dealer()
	{
		__dealer=new Dealer();
	  	seqID=consts.long_min;
	  	companyName="";
	  	linkman1="";
	  	linkman2="";
	  	telephone1="";
	  	telephone2="";
	  	mobile1="";
	  	mobile2="";
	  	remark="";
	  	state=consts.int_min;
	  // dao=(DealerDao)SpringContext.Context.GetObject("DealerDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"编号");
		colNames.Add("seqID");
		m_colLabels.Add("companyName", @"公司名称");
		colNames.Add("companyName");
		m_colLabels.Add("linkman1", @"联系人1");
		colNames.Add("linkman1");
		m_colLabels.Add("linkman2", @"联系人2");
		colNames.Add("linkman2");
		m_colLabels.Add("telephone1", @"联系电话1");
		colNames.Add("telephone1");
		m_colLabels.Add("telephone2", @"联系电话2");
		colNames.Add("telephone2");
		m_colLabels.Add("mobile1", @"手机1");
		colNames.Add("mobile1");
		m_colLabels.Add("mobile2", @"手机2");
		colNames.Add("mobile2");
		m_colLabels.Add("remark", @"备注");
		colNames.Add("remark");
		m_colLabels.Add("state", @"状态");
		colNames.Add("state");
		m_enum_state= new Hashtable();
		m_enum_state.Add("101", @"正常");
		m_enum_state.Add("100", @"停用");
	  }
	
	}
	public t_dealer(Dealer entity )
	{
		__dealer=entity;
		
	  // dao=(DealerDao)SpringContext.Context.GetObject("DealerDao");
	   if(m_colLabels==null)
	   {
		m_colLabels = new Hashtable();
        m_colNames= new ArrayList();
		m_colLabels.Add("seqID", @"编号");
		colNames.Add("seqID");
		m_colLabels.Add("companyName", @"公司名称");
		colNames.Add("companyName");
		m_colLabels.Add("linkman1", @"联系人1");
		colNames.Add("linkman1");
		m_colLabels.Add("linkman2", @"联系人2");
		colNames.Add("linkman2");
		m_colLabels.Add("telephone1", @"联系电话1");
		colNames.Add("telephone1");
		m_colLabels.Add("telephone2", @"联系电话2");
		colNames.Add("telephone2");
		m_colLabels.Add("mobile1", @"手机1");
		colNames.Add("mobile1");
		m_colLabels.Add("mobile2", @"手机2");
		colNames.Add("mobile2");
		m_colLabels.Add("remark", @"备注");
		colNames.Add("remark");
		m_colLabels.Add("state", @"状态");
		colNames.Add("state");
		m_enum_state= new Hashtable();
		m_enum_state.Add("101", @"正常");
		m_enum_state.Add("100", @"停用");
	  }
	
	}
	public Object uniqueResult(DetachedCriteria dc)
    {
        return dao.uniqueResult(dc);
    }
	 public DetachedCriteria DC 
     {
        	get{return DetachedCriteria.For(typeof(Dealer));}
     }
	public const string ENTITYNAME="t_dealer";
	public const int SEQN0=110;
	
    public void checkAdd()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入编号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("编号是主健，框架要求值不能为0"));				

	
	len=companyName.Trim().Length;
	if(len>50)
		 throw (new Exception("公司名称字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("公司名称不能为空!"));	
	

	
	len=linkman1.Trim().Length;
	if(len>20)
		 throw (new Exception("联系人1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("联系人1不能为空!"));	
	

	
	len=linkman2.Trim().Length;
	if(len>20)
		 throw (new Exception("联系人2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=telephone1.Trim().Length;
	if(len>20)
		 throw (new Exception("联系电话1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=telephone2.Trim().Length;
	if(len>20)
		 throw (new Exception("联系电话2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=mobile1.Trim().Length;
	if(len>20)
		 throw (new Exception("手机1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=mobile2.Trim().Length;
	if(len>20)
		 throw (new Exception("手机2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=remark.Trim().Length;
	if(len>100)
		 throw (new Exception("备注字符长度最长不能超过100,当前长度为"+len.ToString()));	
	

	//try{Convert.ToInt32(state);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	state<consts.int_min+1)
			throw (new Exception("请输入状态"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("companyName", companyName);
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==0)
			return;
		Dealer obj=list[0] as Dealer;
//唯一性异常消息抛出
		if( obj.companyName==companyName)
		{
			throw (new Exception(string.Format("公司名称:{0}已经存在",companyName)));	
		}
	//end unique="yes" 唯一性验证
    }
    public void checkUpdate()
    {
		int len;
	//try{Convert.ToInt64(seqID);}catch{ throw (new Exception("请输入正确的长整数格式"));		}
		if(	seqID<consts.long_min+1)
			throw (new Exception("请输入编号"));
 if(				(				  string.Format("{0}",seqID)				  )=="0")
	 throw (new Exception("编号是主健，框架要求值不能为0"));				

	
	len=companyName.Trim().Length;
	if(len>50)
		 throw (new Exception("公司名称字符长度最长不能超过50,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("公司名称不能为空!"));	
	

	
	len=linkman1.Trim().Length;
	if(len>20)
		 throw (new Exception("联系人1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	else if(len==0)
		throw (new Exception("联系人1不能为空!"));	
	

	
	len=linkman2.Trim().Length;
	if(len>20)
		 throw (new Exception("联系人2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=telephone1.Trim().Length;
	if(len>20)
		 throw (new Exception("联系电话1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=telephone2.Trim().Length;
	if(len>20)
		 throw (new Exception("联系电话2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=mobile1.Trim().Length;
	if(len>20)
		 throw (new Exception("手机1字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=mobile2.Trim().Length;
	if(len>20)
		 throw (new Exception("手机2字符长度最长不能超过20,当前长度为"+len.ToString()));	
	

	
	len=remark.Trim().Length;
	if(len>100)
		 throw (new Exception("备注字符长度最长不能超过100,当前长度为"+len.ToString()));	
	

	//try{Convert.ToInt32(state);}catch{ throw (new Exception("请输入正确的整数格式"));		}
		if(	state<consts.int_min+1)
			throw (new Exception("请输入状态"));

//unique="yes" 唯一性验证
		ICriterion crit=Restrictions.Eq("seqID", seqID);
		crit=Restrictions.Or(crit,Restrictions.Eq("companyName", companyName));
  		IList list=dao.List(dao.DC.Add(crit));
		if(list.Count==1)
			return;
		if(list.Count==0)
			throw (new Exception("该记录已经被删除"));	
		else
			throw (new Exception("改纪录出现重名!"));
    }
    public void add()
    {
        try
        {
            checkAdd();
         	dao.Add(__dealer);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void delByseqID()
    {
    
        try
        {
          dao.Delete(__dealer);
        }
        catch(Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }

    public  void update()
    {
        try
        {
            checkUpdate();
            dao.Update(__dealer);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
   
    public void ExecDataUpdate(int rowNo)
    {
		if(m_updateRow==null)
			return;
		int ii=0;
m_updateRow(rowNo,ii++,				(				  string.Format("{0}",seqID)				  ));	
m_updateRow(rowNo,ii++,companyName);	
m_updateRow(rowNo,ii++,linkman1);	
m_updateRow(rowNo,ii++,linkman2);	
m_updateRow(rowNo,ii++,telephone1);	
m_updateRow(rowNo,ii++,telephone2);	
m_updateRow(rowNo,ii++,mobile1);	
m_updateRow(rowNo,ii++,mobile2);	
m_updateRow(rowNo,ii++,remark);	

    }
    public void ExecHeadInsert()
    {
		if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"编号");
			m_insertHead(ii++,100,"公司名称");
			m_insertHead(ii++,100,"联系人1");
			m_insertHead(ii++,100,"联系人2");
			m_insertHead(ii++,100,"联系电话1");
			m_insertHead(ii++,100,"联系电话2");
			m_insertHead(ii++,100,"手机1");
			m_insertHead(ii++,100,"手机2");
			m_insertHead(ii++,200,"备注");
		}		
    }
    public void ExecDataInsert()
	{
		if(m_insertRow==null)
			return;
		int ii=0;
     	m_insertRow(0,ii++,				(				  string.Format("{0}",seqID)				  ));
     	m_insertRow(0,ii++,companyName);
     	m_insertRow(0,ii++,linkman1);
     	m_insertRow(0,ii++,linkman2);
     	m_insertRow(0,ii++,telephone1);
     	m_insertRow(0,ii++,telephone2);
     	m_insertRow(0,ii++,mobile1);
     	m_insertRow(0,ii++,mobile2);
     	m_insertRow(0,ii++,remark);
    }
    public void ExecDataInsertByQuery(DetachedCriteria dc)
    {
      
         IList list=dao.List(dc); 
        
        if(m_insertHead!=null)
        {
			int ii=0;
			m_insertHead(ii++,60,"编号");
			m_insertHead(ii++,100,"公司名称");
			m_insertHead(ii++,100,"联系人1");
			m_insertHead(ii++,100,"联系人2");
			m_insertHead(ii++,100,"联系电话1");
			m_insertHead(ii++,100,"联系电话2");
			m_insertHead(ii++,100,"手机1");
			m_insertHead(ii++,100,"手机2");
			m_insertHead(ii++,200,"备注");
		}		
		
      if(m_insertRow!=null)
      {
        int j=0;
        foreach(Dealer obj in list)			
        {
		  int ii=0;
	     
m_insertRow(j,ii++,				(				  string.Format("{0}",obj.seqID)
				  )
);
m_insertRow(j,ii++,obj.companyName.ToString());
m_insertRow(j,ii++,obj.linkman1.ToString());
m_insertRow(j,ii++,obj.linkman2.ToString());
m_insertRow(j,ii++,obj.telephone1.ToString());
m_insertRow(j,ii++,obj.telephone2.ToString());
m_insertRow(j,ii++,obj.mobile1.ToString());
m_insertRow(j,ii++,obj.mobile2.ToString());
m_insertRow(j,ii++,obj.remark.ToString());
		j++;
        }
        

	
       }
    }

    
    public IList List(DetachedCriteria dc)
    {
        try
        {
           
            return dao.List(dc);
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
        }
    }
    
    public bool Init(DetachedCriteria dc)
    {
    
    		Dealer obj=dao.Get(dc);
    		if(obj==null)
    			return false;
    		else
    		{
    			__dealer=obj;
            	return true;
            }
        
    }
    public static t_dealer Get(DetachedCriteria dc)
    {
    	
    	Dealer obj=((DealerDao)SpringContext.Context.GetObject("DealerDao"))
	 	.Get(dc);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_dealer( obj );
        
    }
	 public static t_dealer GetBySeqID(long val)
	 {
	 	Dealer obj=((DealerDao)SpringContext.Context.GetObject("DealerDao"))
	 	.GetBySeqID(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_dealer( obj );
	 	
	 	
	 }
	 public  bool InitBySeqID(long val)
	 {
	 	

	 	Dealer obj=dao.GetBySeqID(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__dealer=obj;
	 		return true;
	 	}
	 	
	 	
	 }
	 public static t_dealer GetByCompanyName(String val)
	 {
	 	Dealer obj=((DealerDao)SpringContext.Context.GetObject("DealerDao"))
	 	.GetByCompanyName(val);
	 	if(obj==null)
	 		return null;
	 	else
	 		return new t_dealer( obj );
	 	
	 	
	 }
	 public  bool InitByCompanyName(String val)
	 {
	 	

	 	Dealer obj=dao.GetByCompanyName(val) ;
	 	if(obj==null)
	 		return false;
	 	else
	 	{
	 		__dealer=obj;
	 		return true;
	 	}
	 	
	 	
	 }
    
       public bool showInForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			Controls["seqID"].Text=				(				  string.Format("{0}",seqID)				  );
		}
		if(Controls["companyName"]!=null)
		{
			Controls["companyName"].Text=companyName;
		}
		if(Controls["linkman1"]!=null)
		{
			Controls["linkman1"].Text=linkman1;
		}
		if(Controls["linkman2"]!=null)
		{
			Controls["linkman2"].Text=linkman2;
		}
		if(Controls["telephone1"]!=null)
		{
			Controls["telephone1"].Text=telephone1;
		}
		if(Controls["telephone2"]!=null)
		{
			Controls["telephone2"].Text=telephone2;
		}
		if(Controls["mobile1"]!=null)
		{
			Controls["mobile1"].Text=mobile1;
		}
		if(Controls["mobile2"]!=null)
		{
			Controls["mobile2"].Text=mobile2;
		}
		if(Controls["remark"]!=null)
		{
			Controls["remark"].Text=remark;
		}
		if(Controls["state"]!=null)
		{
			Controls["state"].Text=	t_dealer.enum_state[state.ToString()].ToString()
;
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    public  t_dealer Init(Dealer item)
    {
        __dealer=item;
        return this;
    }

    
     public bool initByForm(Control.ControlCollection Controls)
    {
        try
        {
             
		if(Controls["seqID"]!=null)
		{
			
			if(Controls["seqID"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["seqID"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{seqID=(v==""?consts.long_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("编号格式不正确！！"));
				}
				
			}
			else
			{
				try{seqID=(Controls["seqID"].Text==""?consts.long_min:Convert.ToInt32(Controls["seqID"].Text));}
				catch
				{
					 Controls["seqID"].Focus();
					throw  (new Exception("编号格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["companyName"]!=null)
		{
			
			if(Controls["companyName"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["companyName"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{companyName=v;}
				catch
				{
					 Controls["companyName"].Focus();
					throw  (new Exception("公司名称格式不正确！！"));
				}
				
			}
			else
			{
				try{companyName=Controls["companyName"].Text;}
				catch
				{
					 Controls["companyName"].Focus();
					throw  (new Exception("公司名称格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["linkman1"]!=null)
		{
			
			if(Controls["linkman1"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["linkman1"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{linkman1=v;}
				catch
				{
					 Controls["linkman1"].Focus();
					throw  (new Exception("联系人1格式不正确！！"));
				}
				
			}
			else
			{
				try{linkman1=Controls["linkman1"].Text;}
				catch
				{
					 Controls["linkman1"].Focus();
					throw  (new Exception("联系人1格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["linkman2"]!=null)
		{
			
			if(Controls["linkman2"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["linkman2"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{linkman2=v;}
				catch
				{
					 Controls["linkman2"].Focus();
					throw  (new Exception("联系人2格式不正确！！"));
				}
				
			}
			else
			{
				try{linkman2=Controls["linkman2"].Text;}
				catch
				{
					 Controls["linkman2"].Focus();
					throw  (new Exception("联系人2格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["telephone1"]!=null)
		{
			
			if(Controls["telephone1"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["telephone1"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{telephone1=v;}
				catch
				{
					 Controls["telephone1"].Focus();
					throw  (new Exception("联系电话1格式不正确！！"));
				}
				
			}
			else
			{
				try{telephone1=Controls["telephone1"].Text;}
				catch
				{
					 Controls["telephone1"].Focus();
					throw  (new Exception("联系电话1格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["telephone2"]!=null)
		{
			
			if(Controls["telephone2"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["telephone2"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{telephone2=v;}
				catch
				{
					 Controls["telephone2"].Focus();
					throw  (new Exception("联系电话2格式不正确！！"));
				}
				
			}
			else
			{
				try{telephone2=Controls["telephone2"].Text;}
				catch
				{
					 Controls["telephone2"].Focus();
					throw  (new Exception("联系电话2格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["mobile1"]!=null)
		{
			
			if(Controls["mobile1"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["mobile1"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{mobile1=v;}
				catch
				{
					 Controls["mobile1"].Focus();
					throw  (new Exception("手机1格式不正确！！"));
				}
				
			}
			else
			{
				try{mobile1=Controls["mobile1"].Text;}
				catch
				{
					 Controls["mobile1"].Focus();
					throw  (new Exception("手机1格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["mobile2"]!=null)
		{
			
			if(Controls["mobile2"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["mobile2"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{mobile2=v;}
				catch
				{
					 Controls["mobile2"].Focus();
					throw  (new Exception("手机2格式不正确！！"));
				}
				
			}
			else
			{
				try{mobile2=Controls["mobile2"].Text;}
				catch
				{
					 Controls["mobile2"].Focus();
					throw  (new Exception("手机2格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["remark"]!=null)
		{
			
			if(Controls["remark"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["remark"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{remark=v;}
				catch
				{
					 Controls["remark"].Focus();
					throw  (new Exception("备注格式不正确！！"));
				}
				
			}
			else
			{
				try{remark=Controls["remark"].Text;}
				catch
				{
					 Controls["remark"].Focus();
					throw  (new Exception("备注格式不正确！！"));
				}
				
			}
				
				
		}
		if(Controls["state"]!=null)
		{
			
			if(Controls["state"].GetType().Name=="ComboBox")
			{
				ComboBox box=(ComboBox)Controls["state"];
				
				string v=box.SelectedValue==null?box.Text:Convert.ToString(box.SelectedValue);
				try{state=(v==""?consts.int_min:Convert.ToInt32(v));}
				catch
				{
					 Controls["state"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
			else
			{
				try{state=(Controls["state"].Text==""?consts.int_min:Convert.ToInt32(Controls["state"].Text));}
				catch
				{
					 Controls["state"].Focus();
					throw  (new Exception("状态格式不正确！！"));
				}
				
			}
				
				
		}
			return true;
        }
        catch (Exception ex)
        {
            throw (new Exception(ex.Message));
            
        }
    }
    

}

}
